{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提示词 #\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    #api_key=os.getenv(\"DASHSCOPE_API_KEY\"),\n",
    "    api_key=\"sk-b571bfbe652b4ec68ac0491e33949622\", # 这种写法不好，泄露了api-key。 回头正式部署时改掉。\n",
    "    base_url=\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n",
    ")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "员工在报销过程中确保发票真实性的方法包括：\n",
      "\n",
      "1. **个人责任**：出差人员应对相关费用票据来源的合法性、内容的真实性负责。\n",
      "\n",
      "2. **合法合规**：报销的各类发票必须真实有效、合法合理，票据完整无损，内容填列齐全。\n",
      "\n",
      "3. **分类管理**：附上原始单据进行分类粘贴，并按不同城市分别粘贴发票，方便分类计算报销金额。\n",
      "\n",
      "4. **发票验证**：员工获取发票后，需在国家税务局网站验证发票真伪（除特定类别外的所有发票均需验证），并保存验证证明。\n",
      "\n",
      "通过这些步骤，可以有效地保证报销过程中发票的真实性和合法性。\n"
     ]
    }
   ],
   "source": [
    "def llm_qa_prompt(query, context_str):\n",
    "    prompt = f\"\"\"\\\n",
    "    ---------------------\\\n",
    "    # OBJECTIVE #\n",
    "    You are a QA assistant.\n",
    "    Context information is below. Given the context information and not prior knowledge, \\\n",
    "    answer the query.\\\n",
    "    ---------------------\\\n",
    "    # STYLE #\n",
    "    风格应保持结构清晰且简洁易读。\n",
    "    ---------------------\\\n",
    "    Reply in Chinese. \\\n",
    "    若Context information中未涉及客户的问题，应回复：“这个问题不在知识范围之内，现阶段暂时无法回答”\\\n",
    "    ---------------------\\\n",
    "    {context_str}\\\n",
    "    ---------------------\\\n",
    "    \"\"\"\n",
    "    completion = client.chat.completions.create(\n",
    "        model=\"qwen2-7b-instruct\",\n",
    "        messages=[{'role': 'system', 'content': prompt},\n",
    "                  {'role': 'user', 'content': query}],\n",
    "        )\n",
    "    return completion.choices[0].message.content\n",
    "\n",
    "context_str = \"\"\"\n",
    "section 1 start:2.  发票粘贴及管理要求 sction 1 ends.\n",
    "section 2 start:2.1         A4纸横向粘贴，左上角对齐。页眉处写好0A流程编号，部门及姓名， 报销合计金额。注意一个流程对应一笔金额，发票单独粘贴。示例见附 件 sction 2 ends.\n",
    "section 3 start:2.1.1  出差人员应对相关费用票据来源的合法性、内容的真实性负责，严格按 规定开支差旅费。报销的各类发票，必须真实有效、合法合理，票据须 完整无损，内容填列齐全，所附原始单据要分类粘贴，分类计算报销金 额，原则上不同城\n",
    "市的发票分别粘贴在不同的粘贴单上，方便分类计算。 sction 3 ends.\n",
    "section 4 start:2.4         员工报销必须提供真实有效的发票，本人为发票真实性负责，如后期税 务稽查发现虚假发票员工需自行承担相应的责任(不限于罚款、滞纳金、 个人诚信等)及税务现场情况说明。为了防止虚假发票的现象发生，员 工取得发票\n",
    "后要求先在国家税局网站鉴别发票真伪(除交通工具类和交  通费外所有发票都需查验)查询完发票真伪后，把鉴定证明截屏打印附 在发票后面一起交到财务部门。 sction 4 ends.\n",
    "section 5 start:3.1.11 其他类型：其他类型发票按照实际的名目填写，也可先与财务沟通后填 写。 sction 5 ends.\n",
    "section 6 start:员工在自助服务门户填写一般报销，根据实际发票费用类型录入收据信 sction 6 ends.\n",
    "section 7 start:3.1.5      办公费：如办公用品、耗材、电脑配件等，发票内容为具体购买商品明  细，不能笼统的开项目统称，有实物的需要办理入库手续及提供入库单。 sction 7 ends.\n",
    "section 8 start:3.1.4  购书费：购书发票需附供应商盖章的购书清单，方可有效。 sction 8 ends.\n",
    "section 9 start:第四部分报销时间及发票管理 sction 9 ends.\n",
    "\"\"\"\n",
    "query = \"在报销过程中，员工应如何确保发票的真实性？\"   \n",
    "summary_text = llm_qa_prompt(query,context_str) \n",
    "print(summary_text)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
